home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0058_Re: Delphi Cut-Paste.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-24  |  2.1 KB  |  87 lines

  1. {
  2. I don't know if this will help you, but the following (simple) functions
  3. helped me handling substrings. Perhaps you can use them to seperate
  4. the text for each field (for i := 1 to NumToken do ...) and store it
  5. seperatly in the database-fields. }
  6.  
  7. function GetToken(aString, SepChar: String; TokenNum: Byte):String;
  8. {
  9. parameters: aString : the complete string
  10.             SepChar : a single character used as separator 
  11.                       between the substrings
  12.             TokenNum: the number of the substring you want
  13. result    : the substring or an empty string if the are less then
  14.             'TokenNum' substrings
  15. }
  16. var
  17.    Token     : String;
  18.    StrLen    : Byte;
  19.    TNum      : Byte;
  20.    TEnd      : Byte;
  21.  
  22. begin
  23.      StrLen := Length(aString);
  24.      TNum   := 1;
  25.      TEnd   := StrLen;
  26.      while ((TNum <= TokenNum) and (TEnd <> 0)) do
  27.      begin
  28.           TEnd := Pos(SepChar,aString);
  29.           if TEnd <> 0 then
  30.           begin
  31.                Token := Copy(aString,1,TEnd-1);
  32.                Delete(aString,1,TEnd);
  33.                Inc(TNum);
  34.           end
  35.           else
  36.           begin
  37.                Token := aString;
  38.           end;
  39.      end;
  40.      if TNum >= TokenNum then
  41.      begin
  42.           GetToken1 := Token;
  43.      end
  44.      else
  45.      begin
  46.           GetToken1 := '';
  47.      end;
  48. end;
  49.  
  50. function NumToken(aString, SepChar: String):Byte;
  51. {
  52. parameters: aString : the complete string
  53.             SepChar : a single character used as separator 
  54.                       between the substrings
  55. result    : the number of substrings
  56. }
  57.  
  58. var
  59.    RChar     : Char;
  60.    StrLen    : Byte;
  61.    TNum      : Byte;
  62.    TEnd      : Byte;
  63.  
  64. begin
  65.      if SepChar = '#' then
  66.      begin
  67.           RChar := '*'
  68.      end
  69.      else
  70.      begin
  71.          RChar := '#'
  72.      end;
  73.      StrLen := Length(aString);
  74.      TNum   := 0;
  75.      TEnd   := StrLen;
  76.      while TEnd <> 0 do
  77.      begin
  78.           Inc(TNum);
  79.           TEnd := Pos(SepChar,aString);
  80.           if TEnd <> 0 then
  81.           begin
  82.                aString[TEnd] := RChar;
  83.           end;
  84.      end;
  85.      NumToken1 := TNum;
  86. end;
  87.